﻿namespace DesignModeConsole.结构型.代理模式;

/// <summary>
/// 通过让代理类继承自原始类来实现代理模式
/// </summary>
internal class UserService2
{
    public string GetUserName(int userId)
    {
        return "用户名" + userId;
    }

    public bool Login(string account, string password)
    {
        return account == "admin" && password == "123456";
    }
}

/// <summary>
/// 用户服务代理类
/// </summary>
internal class UserServiceProxy2 : UserService2
{
    private readonly MetricsService _metricsService;

    public UserServiceProxy2()
    {
        _metricsService = new MetricsService();
    }

    public new string GetUserName(int userId)
    {
        _metricsService.WriteLog($"记录请求时间 内容是：{userId}");

        return base.GetUserName(userId);
    }

    public new bool Login(string account, string password)
    {
        _metricsService.WriteLog($"记录请求日志 内容是：account：{account}  password：{password}");
        return base.Login(account, password);
    }
}